home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / dev / misc / TechLib.lha / TechLib / resend.c next >
Encoding:
C/C++ Source or Header  |  1996-03-24  |  4.9 KB  |  179 lines

  1. /* resend.c */
  2.  
  3. #include "sh/sub.h"
  4. #include "exec/io.h"
  5. #include "exec/memory.h"
  6. #include "exec/libraries.h"
  7. #include "exec/execbase.h"
  8. #include "dos/dos.h"
  9. #include "dos/dostags.h"
  10. #include "fidonet.h"
  11. #include "techprg.h"
  12. #include "proto/exec_protos.h"
  13. #include "proto/dos_protos.h"
  14.  
  15. #define TRUE 1
  16. #define FALSE 0
  17.  
  18. /* Here are the tech.lib function prototypes. */
  19.  
  20. extern ULONG stoa(u_char *,struct NetAddr *),RexxCmd(UBYTE *);
  21. extern long NumRexxFnc(u_char *);
  22. extern u_char *RexxFnc(u_char *);
  23. extern void *SendBBSMsg(UWORD,void *),InitTech(void),CloseTech(void);
  24.  
  25. int _main(void);
  26. ULONG FindMsg(void),getdate(u_char *);
  27. struct FMsg *LoadMsg(ULONG);
  28. void error(u_char *),cleanup(void);
  29.  
  30. extern u_char APortName[32];
  31.  
  32. struct RdArds *ra;
  33. struct MsgReq mr;
  34. struct NetAddr addr;
  35. struct DateStamp ds;
  36.  
  37. ULONG args[8],area,date,msg,max;
  38.  
  39. BPTR pkt;
  40.  
  41. #define arg_pkt     (u_char *)args[0]
  42. #define arg_from   *((ULONG *)args[1])
  43. #define arg_to     *((ULONG *)args[2])
  44. #define arg_date    (u_char *)args[3]
  45. #define arg_origin  (u_char *)args[4]
  46. #define arg_dest    (u_char *)args[5]
  47. #define arg_pw      (u_char *)args[6]
  48. #define arg_netmail (u_char *)args[7]
  49.  
  50. u_char DayBuf[48],DateBuf[48],TimeBuf[48];
  51.  
  52. struct DateTime timedate = { 0,0,0,FORMAT_DOS,0,DayBuf,DateBuf,TimeBuf };
  53.  
  54. u_char template[]="PKTNAME/A,FROM/A/N,TO/A/N,DATE/A,ORIGIN/A,DESTINATION/A,PASSWORD/K,NETMAIL/S",ver[]="$VER: resend 1.00",
  55.     cmd[32],buf[128],secbuf[128],err_are[]="ARexx error";
  56.  
  57. int _main(void) {
  58. LONG i,o,p,e,t;
  59. u_char *s;
  60. struct FMsg *fmsg;
  61.     GetProgramName(cmd,32);
  62.     if(!(ra=ReadArgs(template,args,NULL))) {
  63.         PrintFault(i=IoErr(),cmd);
  64.         exit(i);
  65.     }
  66.     InitTech();
  67.     pkt=MakePkt(arg_pkt,arg_origin,arg_dest,arg_pw);
  68.     strcpy(APortName,"Tech_0");
  69.     strcpy(DateBuf,arg_date);
  70.     strcpy(TimeBuf,"00:00:00");
  71.     StrToDate(&timedate);
  72.     stoa(arg_origin,&addr);
  73.     t=0;
  74.     date=timedate.dat_Stamp.ds_Days;
  75.     for(area=arg_from;area<=arg_to;area++) {
  76.         if(!(p=FindMsg())) printf("\n\nNo messages.\n"); else {
  77.             printf("\n\nFirst message: %ld. Exporting: ",p);
  78.             Flush(Output());
  79.             e=0;
  80.             for(i=p;i<=max;i++) {
  81.                 if(fmsg=LoadMsg(i)) {
  82.                     if(addr.Zone==fmsg->OrigZone)
  83.                     if(addr.Net==fmsg->OrigNet)
  84.                     if(addr.Node==fmsg->OrigNode)
  85.                     if(addr.Point==fmsg->OrigPoint) {
  86.                         printf("%ld ",i);
  87.                         s=fmsg->DateTime;
  88.                         for(p=0;p<9;p++) {
  89.                             if(*s=='-') *s=32;
  90.                             s++;
  91.                         }
  92.                         MakeMsg(pkt,fmsg->DateTime,arg_netmail?MSGF_PRIVATE:0);
  93.                         s=(u_char *)fmsg->DateTime+20;
  94.                         while(*s++);
  95.                         strcpy(buf,s);
  96.                         while(*s++);
  97.                         Write(pkt,s,strlen(s)+1);
  98.                         Write(pkt,buf,strlen(buf)+1);
  99.                         while(*s++);
  100.                         Write(pkt,s,strlen(s)+1);
  101.                         while(*s++);
  102.                         Write(pkt,s,strlen(s)+1);
  103.                         e++;
  104.                         Flush(Output());
  105.                     }
  106.                     FreeVec(fmsg);
  107.                 }
  108.             }
  109.             printf("%ld messages.\n",e);
  110.             t+=e;
  111.         }
  112.     }
  113.     printf("\nDone! Exported %ld messages.\n",t);
  114.     cleanup();
  115.     return(RETURN_OK);
  116. };
  117.  
  118. /* Find the first message entered at the specified date or later. */
  119.  
  120. ULONG FindMsg(void) {
  121. LONG msg,flag,temp;
  122. struct FMsg *fmsg;
  123.     printf("\nArea %ld. Scanning: ",area);
  124.     sprintf(buf,"GetHighMsg 0 %ld",area);
  125.     if(!(max=NumRexxFnc(buf))) error(err_are);
  126.     msg=max;
  127.     if(area==52) {
  128.         printf("1715 ");
  129.         return(1715);
  130.     }
  131.     flag=FALSE;
  132.     while(TRUE) {
  133.         printf("%ld ",msg);
  134.         Flush(Output());
  135.         if(fmsg=LoadMsg(msg)) {
  136.             temp=getdate(fmsg->DateTime);
  137.             FreeVec(fmsg);
  138.             if(!flag) if(temp>=date) {
  139.                 msg-=50;
  140.                 if(msg<1) { msg=1; flag=TRUE; }
  141.             } else { flag=TRUE; msg++; } else if(temp>=date) return(msg);
  142.                 else if(++msg>max) return(0);
  143.         } else if(msg<max) msg++; else return(0);
  144.     }
  145. };
  146.  
  147. /* This function returns the date of the message as number of days. */
  148.  
  149. ULONG getdate(u_char *datestring) {
  150.     strcpy(DateBuf,datestring);
  151.     StrToDate(&timedate);
  152.     return(timedate.dat_Stamp.ds_Days);
  153. };
  154.  
  155. /* This function loads a message from the message base. */
  156.  
  157. struct FMsg *LoadMsg(ULONG MsgNum) {
  158. struct LoadedMsg *LM;
  159.     mr.Area=area;
  160.     mr.MsgNum=MsgNum;
  161.     LM=SendBBSMsg(ID_LOADMSG,&mr);
  162.     return(LM?LM->msg:NULL);
  163. };
  164.  
  165. /* This function is required by tech.lib. */
  166.  
  167. void error(u_char *str) {
  168.     printf("%s: %s\n",cmd,str);
  169.     cleanup();
  170.     exit(RETURN_FAIL);
  171. };
  172.  
  173. void cleanup(void) {
  174.     if(pkt) ClosePkt(pkt);
  175.     CloseTech();
  176.     if(ra) FreeArgs(ra);
  177. };
  178.  
  179.